<?php
/**
 * Created by PhpStorm.
 * User: peter
 * Date: 2018/7/3
 * Time: 上午9:23
 */

namespace app\mall\controller;


use think\Request;

class Pay extends Auth
{
    /**
     * @purpose 支付升级成为代理商
     * @return array
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function payUpgradeAgent ()
    {
        return \app\mall\logic\Pay::payUpgradeAgent(self::$uid);
    }
    /**
     * @purpose 用户升级代理商微信支付同步回调
     * @param Request $request
     * @return array
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function wechatUpgradeAgentSync (Request $request)
    {
        $order_no           = $request->post('order_no');
        return \app\mall\logic\Pay::wechatUpgradeAgentSync($order_no, self::$uid);
    }
    /**
     * @purpose 支付
     * @param Request $request
     * @return array
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function pay (Request $request) {
        $order_no       = $request->post('order_no');
        $pay_type       = $request->post('pay_type');
        return \app\mall\logic\Pay::pay($order_no, $pay_type, self::$uid);
    }

    /**
     * @purpose 微信支付同步回调
     * @param Request $request
     * @return array
     * @throws \EasyWeChat\Kernel\Exceptions\HttpException
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \Psr\SimpleCache\InvalidArgumentException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function wechatSync (Request $request)
    {
        $order_no       = $request->post('order_no');
        return \app\mall\logic\Pay::wechatSyncCallback($order_no, self::$uid);
    }
}